package common

import (
	"fishDemo/model"
	"fmt"
	"github.com/jinzhu/gorm"
)

var DbCon *gorm.DB

func initDB() *gorm.DB {
	driverName := "mysql"
	host := "10.211.55.5"
	port := "3306"
	username := "root"
	password := "lxh991130"
	dbname := "fishDemo"
	timout := "10s"
	args := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local&timeout=%s", username, password, host, port, dbname, timout)
	db, err := gorm.Open(driverName, args)
	if err != nil {
		fmt.Println("faild to connect databses , rror:" + err.Error())
	}
	db.AutoMigrate(&model.User{})
	return db
}

func GetDB() *gorm.DB {
	DbCon = initDB()
	return DbCon
}
